/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ronin.dao.api;

import com.ronin.model.Musteri;
import com.ronin.model.kriter.MusteriSorguKriteri;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 *
 * @author esimsek
 */
@Repository
public class MusteriDao implements IMusteriDao {

    @Autowired
    private SessionFactory sessionFactory;

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    @Override
    public Musteri getSingle(Musteri musteri) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Musteri getSingleById(Long id) {
        List list = getSessionFactory().getCurrentSession()
                .createQuery("from Musteri where id=?")
                .setParameter(0, id).list();
        return (Musteri) list.get(0);
    }

    @Override
    public Musteri getSingleOneByNamedQuery(String namedQuery, Object... parameters) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<Musteri> getListCriteriaForPaging(int first, int pageSize, MusteriSorguKriteri sorguKriteri) {
        Query q = getSessionFactory().getCurrentSession().createQuery("from Musteri ");
        q.setFirstResult(first);
        q.setMaxResults(pageSize);
        List list = q.list();
        return list;
    }

    @Override
    public int getCountByCriteriaForPaging(MusteriSorguKriteri sorguKriteri) {
        List list = getSessionFactory().getCurrentSession()
                .createQuery("select count(M.id) from Musteri M").list();
        return ((Long) list.get(0)).intValue();
    }

    @Override
    public List<Musteri> getList(Musteri musteri) {
        List list = getSessionFactory().getCurrentSession()
                .createQuery("from Musteri ").list();
        String sorgu = " SELECT ";
        Query q = null;

        return list;
    }

    private Query sorguHazirla(MusteriSorguKriteri sorguKriteri, String prefix) {
        String sorgu = prefix + " FROM Musteri M WHERE 1=1";
        return null;
    }

    @Override
    public List<Musteri> getListByNamedQuery(String namedQuery, Object... parameters) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int getCount(Musteri musteri) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void add(Musteri musteri) {
        getSessionFactory().getCurrentSession().save(musteri);
    }

    @Override
    public void update(Musteri musteri) {
        getSessionFactory().getCurrentSession().update(musteri);
    }

    @Override
    public void delete(Musteri musteri) {
        //musteri.setDurum(DurumEnum.Silinmis);
        this.update(musteri);
    }

}
